<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h = "http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui">
    <ui:fragment>
        <!-- Updated by login button-->
        <h:panelGroup id="log" >
            <!-- If the user is logged in and admin, show a friendly messag-->
            <h:panelGroup rendered="#{loginModelBean.loggedIn == true and loginModelBean.admin == true}">
                <h:outputText value="You are logged in!" />
                <br/>
                <br/>
                <h:form>
                    <p:commandButton value="Logout" action="/logout.xhtml?faces-redirect=true" actionListener="#{loginControllerBean.logout()}" />
                    &nbsp;
                    <p:button value="Administration" outcome="goToAdmin" />
                </h:form>
            </h:panelGroup>
            <h:panelGroup rendered="#{loginModelBean.loggedIn == true and loginModelBean.admin == false}">
                <h:outputText value="You are logged in!" />
                <br/>
                <br/>
                <h:form>
                    <p:commandButton value="Logout" action="/logout.xhtml?faces-redirect=true" actionListener="#{loginControllerBean.logout()}" />
                </h:form>
            </h:panelGroup>
            <!-- If the user is not logged in, Show a log in window -->
            <h:panelGroup rendered="#{loginModelBean.loggedIn == false}">
                <h:form>
                    <td>
                        <h:outputLabel value="Email:" /> 
                    </td>
                    <td>
                        <h:inputText value="#{loginModelBean.email}" />
                    </td>
                    <td>
                        <h:outputLabel value="Password: " />
                    </td>
                    <td>
                        <h:inputSecret value="#{loginModelBean.password}"/>
                    </td>
                    <!-- Log in-button, tries to log in and updates the log in window and the buy window... -->
                    <p:commandButton update=":log, :buyForm, :adminForm, :addProductForm" value="Login" actionListener="#{loginControllerBean.login()}" />
                    <br/>
                    <h:link value="Register Now!" outcome="registerCustomer" />
                </h:form>
            </h:panelGroup>
            <br/>
            <!-- Show a message from the LoginController. Either you are logged in or log in was failed -->
            <p:messages globalOnly="true" showDetail="true" />
        </h:panelGroup>
    </ui:fragment>
</html>
